<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>重置密码</title>
    <#include "admin/common/header.ftl"/>
<body>
<div class="container-fixed-xs">
<div style="margin-left: 20px; margin-right: 20px; padding-top: 100px; padding-bottom: 100px;">
    <center><h2>重置密码</h2></center>
    <form id="resetForm" method="post" action="/reset">
        <div class="form-group">
            <label for="passWord" class="required">新密码</label>
            <input type="password" class="form-control" id="passWord" name="passWord" placeholder="请输入新密码">
        </div>
        <div class="form-group">
            <label for="rpassWord" class="required">确认密码</label>
            <input type="password" class="form-control" id="rpassWord" name="rpassWord" placeholder="请输入确认密码">
        </div>
        <div>密码长度8~16位，数字、字母、字符至少包含两种</div>
        <div class="form-group">
            <button type="submit" class="btn btn-large btn-block btn-primary">提交</button>
            <button type="button" class="btn btn-large btn-block btn-primary" id="resetBtn">重置</button>
        </div>
    </form>
</div>
</div>
<script>
    // 重置密码
    $(document).ready(function() {
        $('#resetForm').bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                passWord: {
                    message: '新密码验证失败',
                    validators: {
                        notEmpty: {
                            message: '新密码不能为空'
                        },
                        stringLength: {
                            min: 5,
                            max: 18,
                            message: '密码长度必须在5到18位之间'
                        },
                        regexp: {
                            regexp: /^[a-zA-Z0-9_]+$/,
                            message: '密码只能包含大写、小写、数字和下划线'
                        }
                    }
                },
                rpassWord: {
                    message: '确认密码验证失败',
                    validators: {
                        notEmpty: {
                            message: '确认密码不能为空'
                        },
                        identical: {
                            field: 'passWord',
                            message: '两次密码不一致'
                        }
                    }
                }
            }
        }).on('success.form.bv',function (e) {
            // Prevent form submission
            e.preventDefault();

            // Get the form instance
            var $form = $(e.target);

            // Get the BootstrapValidator instance
            var bv = $form.data('bootstrapValidator');

            // Use Ajax to submit form data
            $.post($form.attr('action'), $form.serialize(), function(result) {
                console.log(result);
                if (result.errorCode == 'y') {
                    location.href = "http://localhost:8080/";
                } else {
                    new $.zui.Messager('提示消息：' + result.errorText, {
                        icon: 'exclamation-sign',
                        type: 'danger',
                        time: 2000
                    }).show();
                }
            }, 'json');
        });
        $('#resetBtn').click(function() {
            $('#resetForm').data('bootstrapValidator').resetForm(true);
        });
    });
</script>
<style>
    body {
        /*background: url(../static/images/back.jpg) no-repeat 0 0px;*/
        background-color: #F0F0F0;
        background-attachment:fixed;
        background-size:100%;
        height:auto;
    }
</style>
</body>
</html>